﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Mercator2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                //string ID = "9661112308";//your datakey value here;       //your "s" string variable
                
                //DataView dv = (DataView)Mercator.Select(DataSourceSelectArguments.Empty);
                //if (dv != null)
                //{
                //    dv.Sort = "DeviceID";       //this should be the primary key - may have to change it appropriately
                //    int index = dv.Find(ID);
                //    if (index > 0)
                //    {
                //            DetailsView1.PageIndex = index;
                //            DetailsView1.DataBind(); 
                //    }
                //}
            }
        }

        protected void DetailsView1_DataBound(object sender, EventArgs e)
        {
            // Get the pager row.

            //DetailsViewRow pagerRow = DetailsView1.BottomPagerRow;

            // Get the Label controls that display the current page information 

            // from the pager row.

            //Label pageNum = (Label)pagerRow.Cells[0].FindControl("PageNumberLabel");
            //Label totalNum = (Label)pagerRow.Cells[0].FindControl("TotalPagesLabel");

            //if ((pageNum != null) && (totalNum != null))
            //{
            //    // Update the Label controls with the current page values.

            //    int page = DetailsView1.DataItemIndex + 1;
            //    int count = DetailsView1.DataItemCount;

            //    pageNum.Text = page.ToString();
            //    totalNum.Text = count.ToString();
            //}

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string ID = this.txtDeviceID.Text;//"9661112308";//your datakey value here;       //your "s" string variable

            DataView dv = (DataView)Mercator.Select(DataSourceSelectArguments.Empty);
            if (dv != null)
            {
                dv.Sort = "DeviceID";       //this should be the primary key - may have to change it appropriately
                int index = dv.Find(ID);
                if (index >= 0)
                {
                    DetailsView1.PageIndex = index;
                    DetailsView1.DataBind();
                }
            }
        }
    }
}